{extend name='base' /}

{block name='main'}
<div class="main-panel">
    <div class="content">
        <div class="page-inner">
            <div class="row">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-header">
                            <h4 class="card-title">优惠</h4>
                        </div>
                        <div class="card-body">
                            {include file='order/goods'/}

                            <div class="tt">
                                修改订单
                            </div>
                            <form id="form">
                                <table cellspacing="0" class="tb w-100">
                                    <tbody class="">
                                    <tr>
                                        <td class="tl">下单时间</td>
                                        <td>
                                            {$order.date_entered}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tl">订单总额</td>
                                        <td class="text-danger">
                                            ￥{php} echo sprintf('%.2f', $order['amount'] + $order['fee']){/php}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tl">附加名称</td>
                                        <td>
                                            <input type="text" name="data[fee_name]" class="form-control" value="{$order.fee_name}">
                                            <div class="text-muted mt-1 ml-1">例如运费、退款、优惠等</div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tl">附加金额</td>
                                        <td>
                                            <input type="number" name="data[fee]" class="form-control" placeholder="单位元" value="{$order.fee}">
                                            <div class="text-muted mt-1 ml-1">单位元，可以为负值</div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tl"></td>
                                        <td>
                                            <button type="button" class="btn btn-success" onclick="add();">立即提交</button>
                                            <button type="button" class="btn btn-danger" onclick="window.history.back()">返回</button>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                <input type="hidden" name="id" value="{$order.id}">
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name='js'}
<script>
    var lock = false
    function add() {
        if (lock) {
            return false;
        }
        lock = true;
        $.ajax({
            url: "{:url('order/discount')}",
            type: 'post',
            data: $("#form").serialize(),
            dataType: 'json',
            success: function (res) {
                if (res.code == 0) {
                    swal("提示", res.msg, {
                        icon : "error",
                        buttons: {
                            confirm: {
                                className : 'btn btn-danger'
                            }
                        },
                    });
                    lock = false;
                }else{
                    window.history.back();
                }
            }
        })
    }
</script>
{/block}